# Maintainer: Alexey Pavlov <alexpux@gmail.com>
# Contributor: Ray Donnelly <mingw.android@gmail.com>
# Contributor: Marcin Sielski <marcin.sielski@motorolasolutions.com>

_realname=gst-plugins-bad
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=1.6.3
pkgrel=1
pkgdesc="GStreamer Multimedia Framework Bad Plugins (mingw-w64)"
arch=('any')
url="https://gstreamer.freedesktop.org/"
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "${MINGW_PACKAGE_PREFIX}-gobject-introspection")
depends=("${MINGW_PACKAGE_PREFIX}-celt"
         "${MINGW_PACKAGE_PREFIX}-chromaprint"
         "${MINGW_PACKAGE_PREFIX}-clutter"
         "${MINGW_PACKAGE_PREFIX}-curl"
         "${MINGW_PACKAGE_PREFIX}-daala"
         "${MINGW_PACKAGE_PREFIX}-faad2"
         "${MINGW_PACKAGE_PREFIX}-faac"
         "${MINGW_PACKAGE_PREFIX}-fluidsynth"
         "${MINGW_PACKAGE_PREFIX}-gnutls"
         "${MINGW_PACKAGE_PREFIX}-gsm"
         "${MINGW_PACKAGE_PREFIX}-gst-plugins-base"
         "${MINGW_PACKAGE_PREFIX}-gtk3"
         "${MINGW_PACKAGE_PREFIX}-libdca"
         "${MINGW_PACKAGE_PREFIX}-libdvdnav"
         "${MINGW_PACKAGE_PREFIX}-libexif"
         "${MINGW_PACKAGE_PREFIX}-libgme"
         "${MINGW_PACKAGE_PREFIX}-libjpeg"
         "${MINGW_PACKAGE_PREFIX}-libmimic"
         "${MINGW_PACKAGE_PREFIX}-libmodplug"
         "${MINGW_PACKAGE_PREFIX}-libmpeg2"
         "${MINGW_PACKAGE_PREFIX}-libpng"
         "${MINGW_PACKAGE_PREFIX}-librsvg"
         "${MINGW_PACKAGE_PREFIX}-libwebp"
         "${MINGW_PACKAGE_PREFIX}-libxml2"
         "${MINGW_PACKAGE_PREFIX}-mpg123"
         "${MINGW_PACKAGE_PREFIX}-nettle"
         "${MINGW_PACKAGE_PREFIX}-openal"
         "${MINGW_PACKAGE_PREFIX}-opencv"
         "${MINGW_PACKAGE_PREFIX}-openexr"
         "${MINGW_PACKAGE_PREFIX}-openjpeg2"
         "${MINGW_PACKAGE_PREFIX}-opus"
         "${MINGW_PACKAGE_PREFIX}-orc"
         "${MINGW_PACKAGE_PREFIX}-schroedinger"
         "${MINGW_PACKAGE_PREFIX}-soundtouch"
         "${MINGW_PACKAGE_PREFIX}-openh264")
options=(!libtool strip staticlibs)
source=(${url}/src/${_realname}/${_realname}-${pkgver}.tar.xz
        0002-better-openjpeg2-checking.all.patch
        0004-port-to-openjpeg-2.1.all.patch
        0005-Include-glext-h.patch
        0006-No-X11-on-_WIN32.patch)
sha256sums=('971b29101d6a9c5e3fe94d99d977a227f58f0b2d29b6ca2c7f292052542b3a61'
            'afb2185bd23c1d43ef03336ffbeeef3c68698715471ef76a173e65359a38ff9c'
            '66adeae3cf58faac395654d2443784575c31ecf5390cc6f9e86e9a63e20acaa7'
            '439436d02724c07af95f509647238f271f4717958dcf42dc5adb5a8e6a2108e7'
            'da9b9c1cf8ce5ee77f7963a6ffecc2abfbc8d0e3c4ea88a49646c0c98a480e46')

prepare() {
  cd "${srcdir}"/${_realname}-${pkgver}
  patch -p1 -i "${srcdir}"/0002-better-openjpeg2-checking.all.patch
  patch -p1 -i "${srcdir}"/0004-port-to-openjpeg-2.1.all.patch
  patch -p1 -i "${srcdir}"/0005-Include-glext-h.patch
  patch -p1 -i "${srcdir}"/0006-No-X11-on-_WIN32.patch
  NOCONFIGURE=1 ./autogen.sh
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"
  #CPPFLAGS+=" --save-temps"
  #CFLAGS+=" --save-temps"

  ../${_realname}-${pkgver}/configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    --disable-static \
    --enable-shared \
    --disable-silent-rules \
    --enable-experimental \
    --disable-gtk-doc \
    --with-gtk=3.0

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make -j1 DESTDIR="${pkgdir}" install

  rm -f ${pkgdir}${MINGW_PREFIX}/lib/gstreamer*/*.a
}
